package transport

import (
	"context"
	"dawncloud/services"
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	httptransport "github.com/go-kit/kit/transport/http"
)

func NewHTTPHandler(endpoints services.Endpoints) http.Handler {
	r := gin.Default()

	getSewageDataHandler := httptransport.NewServer(
		endpoints.GetSewageDataEndpoint,
		decodeGetSewageDataRequest,
		encodeResponse,
	)

	r.GET("/sewage-data", func(c *gin.Context) {
		getSewageDataHandler.ServeHTTP(c.Writer, c.Request)
	})

	return r
}

func decodeGetSewageDataRequest(_ context.Context, r *http.Request) (interface{}, error) {
	return nil, nil
}

func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	return json.NewEncoder(w).Encode(response)
}
